Ext.define('PJ.view.registrationmanagement.ChooseUserTree', {
    extend: 'AM.default.DefaultTree',
    alias: ['widget.rtmChooseUserTree'],
    title: "组织机构树",
    
    initComponent: function(){
    	var me = this;
    	this.store = Ext.create('PJ.'+ prototype +'.registrationmanagement.ChooseUserTree');
    	this.addListener("itemclick", function(view, record, htmlelement, index, eventObject, object){
    		if(eventObject){
    			eventObject.stopEvent();
    		}
    		var gridList = this.up("container").down("grid");
    		var gridListStore = gridList.getStore();
    		gridList.recordId = record.data.id;
    		gridList.store.isLoad = true;
			var newParams = {
					searchDepId: record.data.id,
					searchClassID: me.up('window').classId
			};
			var params = gridListStore.proxy.extraParams;
			Ext.apply(params, newParams);
			gridListStore.load();
			gridList.quotaOfPeople();//预授人数统计
			var addButton = gridList.down('#' + this.oldId + "Add");
			if(addButton){
	        	var buttonFlag = record.data.id != 1?false:true;
				addButton.setDisabled(buttonFlag);
			}
    	});
		var treeStore = me.getStore();
		treeStore.setProxy({
			type: gj_onlineLearning_constant.loadType,
			url: treeStore.url+"?classIdd=" +me.classId
		});
        this.callParent(arguments);
        this.loadType = gj_onlineLearning_constant.loadType;
    },
    listeners: {
    	//显示树的一级菜单
		load: function(treeStore, node, records, successful, eOpts){
			if (node.data.id==1&&records != null&&node.hasChildNodes()) {
				if(node.data.id==1)
					this.fireEvent("itemclick",this.view,records[0]); //点击展开节点
			}
		}
    }
});
